package models

import (
	"fmt"
	"github.com/astaxie/beego/httplib"
	"smart_home/mqtt/conf"
)

const (
	EQUIPMENT_SOCKET = 1 // 插座
)

type Equipment struct {
	Id         string `json:"id" form:"id"`
	UserId     string `json:"user_id" form:"user_id"`
	Name       string `json:"name" form:"name"`
	Sta        string `json:"sta" form:"sta"`
	SceneId    string `json:"scene_id" form:"scene_id"`
	Type       int64  `json:"type" form:"type"`
	Password   string `json:"-" form:"password"`
	CreateTime int64  `json:"create_time" form:"create_time"`
	Version    string `json:"version"`
}

type equipmentResult struct {
	HttpResult
	Result *Equipment
}

// 获取设备信息
func GetEquipmentBySta(sta, uid string) (*Equipment, error) {
	res := &equipmentResult{}
	apiUrl := fmt.Sprintf("http://api.rcenet.com/v2/equipment/%s", sta)
	err := httplib.Get(apiUrl).Header("st", conf.SToken).Header("suid", uid).ToJSON(res)
	if err != nil {
		return nil, err
	}
	return res.Result, nil
}
